<?php

/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the controller to call when that URI is requested.
|
*/
require 'Routes/common-routes.php';
require 'Routes/site-routes.php';
require 'Routes/admin-routes.php';
require 'Routes/api-routes.php';

// 测试路由
Route::group(['prefix' => 'tester'], function () {
    Route::any('abort', function () {
//        abort(503);
        throw new \App\B2BProject\Exception\UserTypeException;
    });
    Route::get('password-generate/{password}', function ($password) {
        return bcrypt($password);
    });

    Route::post('upload-test', function (\Illuminate\Http\Request $request) {
        $file = $request->file('upload');

        var_dump([
            $file->getClientOriginalName(),
            $file->getClientMimeType(),
            $file->getClientOriginalExtension(),
            $file->guessClientExtension(),
            $file->getExtension(),
        ]);
    });

    Route::get('brand', function () {
        $stores = \App\B2BProject\Custom\Business\Store::whereHas('mainBrand', function ($q) {
            $q->where('id', 24);
        })->get();

        foreach ($stores as $store) {
            printf("[%s]<br>\n", $store->member->information->company);

            foreach ($store->mainBrand as $brand) {
                printf("-> %s<br>\n", $brand->name);
            }
        }
    });

    Route::get('auth', function () {
        if (Auth::guest()) {
            return redirect()->route('custom.login');
        }

        return Auth::user()->email;
    });

    Route::get('view', function () {
        return view('test');
    });
});
